home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Games&Education / CivHack PM3 / CivHackPM.c next >
C/C++ Source or Header  |  1996-01-08  |  2KB  |  89 lines

  1. // CivHackPCI3
  2.  
  3. // Little hack to get Civilization game to run on PCI Macs.
  4.  
  5. // I make no promises that this won't crash your machine, etc.  You have been 
  6. // warned.
  7.  
  8. // Jan 8 '95
  9. // Gavriel State:
  10. // gav@magmacom.com
  11.  
  12.  
  13. #include "Types.h"
  14. #include "QuickDraw.h"
  15. #include "Windows.h"
  16. #include "Memory.h"
  17. #include "Resources.h"
  18. #include "OSUtils.h"
  19.  
  20. #include "SetupA4.h"
  21. #include "A4Stuff.h"
  22. #include "LowMem.h"
  23.  
  24. // Function Prototypes
  25. pascal void PatchSetCCursor(CCrsrHandle cCrsr);
  26. int main(void);
  27.  
  28. // SetCCursor ProcPtr type definition
  29. typedef pascal void (*SetCCursorProcPtr)(CCrsrHandle cCrsr);
  30.  
  31. // Declare a global pointer to save the original SetCCursor address in
  32. SetCCursorProcPtr        gOldSetCCursor;
  33.  
  34. //---------------------------------------------------------------------------
  35. // The patch function
  36. //---------------------------------------------------------------------------
  37. pascal void PatchSetCCursor(CCrsrHandle cCrsr)
  38. {
  39.     GDHandle    savedGD;
  40.     
  41.     // Set up A4 globals
  42.     EnterCallback();
  43.     
  44.     // Here's the magic: SetCCursor *should* respect the low mem 
  45.     // TheGDevice variable.  On the PowerMacs though, it doesn't.
  46.     // We fix this by saving and restoring the variable before/after
  47.     // the actual call to SetCCursor
  48.     
  49.     // Save theGDevice
  50.     savedGD = LMGetTheGDevice();
  51.     
  52.     // Call the original routine
  53.     (*gOldSetCCursor)(cCrsr);
  54.  
  55.     // Restore theGDevice
  56.     LMSetTheGDevice(savedGD);
  57.  
  58.     // Tear down A4 globals
  59.     ExitCallback();
  60. }
  61.  
  62. //---------------------------------------------------------------------------
  63. // The INIT main and patch installer.
  64. //---------------------------------------------------------------------------
  65. int main(void)
  66. {
  67.     Handle H;
  68.     
  69.     EnterCodeResource();    // Set up for globals    
  70.     PrepareCallback();
  71.     
  72.     // Set up the patch - the INIT *must* be in the Sysheap
  73.     H = GetResource('INIT',0);
  74.     if (H) 
  75.     {
  76.         // Detach and lock the patch
  77.         DetachResource(H);
  78.         HLock(H);
  79.         HNoPurge(H);
  80.  
  81.         // Get the old address
  82.         gOldSetCCursor = (SetCCursorProcPtr)NGetTrapAddress(_SetCCursor, ToolTrap);
  83.         
  84.         // Install the patch
  85.         NSetTrapAddress((UniversalProcPtr)&PatchSetCCursor, _SetCCursor, ToolTrap);
  86.     }
  87.     
  88.     ExitCodeResource();        // Shutdown use of globals (A4).
  89. }